<template>
  <div class="login">
    <el-card class="box-card">
      <div class="login-title">欢迎来到图书管理系统</div>
      <el-form ref="form" :model="form" status-icon :rules="rules" size="small">
        <el-form-item prop="username">
          <el-input
            prefix-icon="el-icon-user-solid"
            type="text"
            v-model="form.username"
            autocomplete="off"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            prefix-icon="el-icon-s-cooperation"
            type="password"
            v-model="form.password"
            autocomplete="off"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">立即登录</el-button>
          <!--<el-button @click="register">注册</el-button>-->
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {status, common} from "../request";

export default {
  data() {
    return {
      form: {},
      rules: {
        username: [{required: true, message: "*必填"}],
        password: [{required: true, message: "*必填"}]
      }
    };
  },
  methods: {
    submitForm() {
      this.$refs.form.validate(async valid => {
        if (!valid) return this.$message.error("请输入必填信息！");

        const data = await common.login(this.form);
        if (data.code == status.SUCCESS) {
          window.sessionStorage.setItem('user-token', data.data.token);
          window.sessionStorage.setItem("user", JSON.stringify(data.data));
          this.$message.success(data.msg);
          this.$router.push("/home");
        }
      });
    },
    register() {
      //this.$router.push("/regist");
    }
  }
};
</script>

<style lang="scss" scoped>
.login {
  position: relative;
  height: 100%;
  color: $font-color;
  background-color: rgba($color: #000000, $alpha: 0.4);

  &::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background-image: url(http://www.sxjczy.cn:88/gb2015/images/2.jpg);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-attachment: fixed;
    filter: blur(3px);
    z-index: -100;
  }

  .box-card {
    z-index: 200;
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translate(-50%);
    min-width: 500px;
    padding: 30px;
  }

  .login-title {
    font-size: 20px;
    margin-bottom: 50px;
  }
}
</style>
